//
//  MerchantCell.m
//  dyseller
//
//  Created by 红喇叭 on 2017/12/5.
//  Copyright © 2017年 红喇叭. All rights reserved.
//

#import "MerchantCell.h"

@implementation MerchantCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        [self initView];
    }
    return self;
}

- (void)initView{
    _coverImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"photo_bg8_default"]];
    [self.contentView addSubview:_coverImg];
    _coverImg.sd_layout.leftSpaceToView(self.contentView, GETWITH(30)).centerYEqualToView(self.contentView).widthIs(GETWITH(160)).heightEqualToWidth();
    
    _defImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"photo_bg10_default"]];
    [self.contentView addSubview:_defImg];
    _defImg.sd_layout.leftSpaceToView(self.contentView, GETWITH(30)).centerYEqualToView(self.contentView).widthIs(GETWITH(160)).heightEqualToWidth();
    _defImg.hidden = YES;
    
    _merchantName = [[UILabel alloc] init];
    _merchantName.textColor = kBlackColor;
    _merchantName.font = font17;
    _merchantName.text = @"个人相册";
    [self.contentView addSubview:_merchantName];
    _merchantName.sd_layout.leftSpaceToView(_coverImg, GETWITH(30)).rightSpaceToView(self.contentView, GETWITH(30)).topEqualToView(_coverImg).heightIs(20);
    
    _photographnNumLab = [[UILabel alloc] init];
    _photographnNumLab.font = font14;
    _photographnNumLab.textColor = kGrayColor;
    _photographnNumLab.text = @"1张照片";
    [self.contentView addSubview:_photographnNumLab];
    _photographnNumLab.sd_layout.leftEqualToView(_merchantName)
    .topSpaceToView(_merchantName, 10).rightEqualToView(_merchantName).heightIs(16);
    
    _editingBtn = [[UIButton alloc] init];
    [_editingBtn setTitle:@"编辑" forState:UIControlStateNormal];
    _editingBtn.titleLabel.font = font12;
    [_editingBtn setTitleColor:MianRedColor forState:UIControlStateNormal];
    [_editingBtn setBackgroundImage:[UIImage imageNamed:@"edit_button3_default_nor"] forState:UIControlStateNormal];
    [self.contentView addSubview:_editingBtn];
    _editingBtn.sd_layout.rightEqualToView(_merchantName).
    widthIs(GETWITH(120)).bottomSpaceToView(self.contentView, 10).heightIs(22);
    _editingBtn.hidden = YES;
    
    //上，下架
    _operateBtn = [[UIButton alloc] init];
    [_operateBtn setTitle:@"下架" forState:UIControlStateNormal];
    _operateBtn.titleLabel.font = font12;
    [_operateBtn setTitleColor:UIColorFromRGB(0xff9000) forState:UIControlStateNormal];
    [_operateBtn setBackgroundImage:[UIImage imageNamed:@"edit_button2_default_nor"] forState:UIControlStateNormal];
    
    [_operateBtn setTitle:@"上架" forState:UIControlStateSelected];
    [_operateBtn setTitleColor:MianRedColor forState:UIControlStateSelected];
    [_operateBtn setBackgroundImage:[UIImage imageNamed:@"edit_button3_default_nor"] forState:UIControlStateSelected];
    [self.contentView addSubview:_operateBtn];
    _operateBtn.sd_layout.rightSpaceToView(_editingBtn, GETWITH(24)).bottomSpaceToView(self.contentView, 10).widthIs(GETWITH(120)).heightIs(22);
    _operateBtn.hidden = YES;
    
    _rightLab = [[UILabel alloc] init];
    _rightLab.text = @"不可编辑";
    _rightLab.font = font12;
    _rightLab.textColor = UIColorFromRGB(0xdbdbdb);
    _rightLab.textAlignment = NSTextAlignmentRight;
    _rightLab.hidden = YES;
    [self.contentView addSubview:_rightLab];
    _rightLab.sd_layout.rightSpaceToView(self.contentView, GETWITH(30)).bottomSpaceToView(self.contentView, 10).widthIs(100).heightIs(16);
    
    _rightImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"photo_bg4_default"]];
    [self.contentView addSubview:_rightImg];
    _rightImg.sd_layout.rightSpaceToView(self.contentView, GETWITH(30)).centerYEqualToView(self.contentView).widthIs(6).heightIs(11);

}

- (void)setIsEdit:(BOOL)isEdit{
    _isEdit = isEdit;
    _operateBtn.hidden = !isEdit;
    _editingBtn.hidden = !isEdit;
}

- (void)setDataModel:(HLBAlbumListModel *)dataModel{
    _dataModel = dataModel;
    [_coverImg sd_setImageWithURL:[NSURL URLWithString:_dataModel.album_cover] placeholderImage:[UIImage imageNamed:@"photo_bg12_default"]];
    _merchantName.text = _dataModel.album_name;
    
    _photographnNumLab.text = [NSString stringWithFormat:@"共%@张图片",_dataModel.img_num];
    
    _operateBtn.selected = [_dataModel.is_enable isEqualToString:@"0"]?YES:NO;
    
    _defImg.hidden = !_operateBtn.selected;
    
}

@end
